package com.zhanglijie.theory.future;

import java.util.concurrent.Callable;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/8/14 0014 23:52
 */
public class FutureProduct implements Product {
    private boolean isReady;
    private RealProduct realProduct;


    public synchronized void setRealProduct(RealProduct realProduct) {
        if(isReady){
            return;
        }
        this.realProduct = realProduct;
        setReady(true);
        notifyAll();
    }

    public synchronized void setReady(boolean ready) {
        isReady = ready;
    }

    @Override
    public synchronized String getContent() throws InterruptedException {
        if(!isReady){
            wait();
        }
        return realProduct.getContent();
    }
}
